package com.chanyachting.emall.serviceImpl;

import java.util.List;

import org.hibernate.Query;

import com.chanyachting.emall.dao.CompanyDAO;
import com.chanyachting.emall.domain.Company;
import com.chanyachting.emall.domain.Companykeyword;
import com.chanyachting.emall.domain.Companyproductcategory;
import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.service.CompanyService;
import com.chanyachting.emall.util.DateUtil;

public class CompanyServiceImpl implements CompanyService {

	private CompanyDAO cDao;

	public CompanyServiceImpl() {

		this.cDao = new CompanyDAO();
	}

	public boolean addCompanyKeyWord(Company company, Companykeyword ckeyword) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean createCompany(Company company, Member member) {

		this.cDao.save(company, member);

		return true;
	}

	public boolean createCompanyYellowPage(Company company) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean delCompanykeyword(Company company, Companykeyword ckeyword) {
		// TODO Auto-generated method stub
		return false;
	}

	public Company getOneCompany(Company company) {

		return (Company) this.cDao.load(Company.class, company.getId());
	}

	public boolean refreshCompany(Company company) {

		company.setRefreshDate(DateUtil.getDate());

		return this.cDao.update(Company.class, company, company.getId());
	}

	public boolean setCompanyproductcategory(Company company,
			Companyproductcategory cpc) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean updateCompany(Company company) {

		// return this.cDao.update(Company.class,company, company.getId());

		this.cDao.update(company);

		return true;
	}

	public boolean updateCompanyYellowPage(Company company) {
		// TODO Auto-generated method stub
		return false;
	}

	public List<Company> getAllCompany() {
		
		return this.cDao.find("from Company order by pri");
	}
	
	public List<Company> getCompanyById(String id){
		return this.cDao.find("from Company where id='" + id +"'");
	}
	
	public List<Company> getAllCompanyByPageBreak(int currentPage,int pageSize) {
		String sqlStr = "from Company order by pri";
		Query q = this.cDao.createQuery(sqlStr);
		q.setMaxResults(pageSize);
		q.setFirstResult(currentPage * pageSize);
		
		return q.list();
	}
}
